<template>
  <!-- 对话框(添加 / 修改) -->
  <el-dialog
    title="请假审核"
    :visible.sync="show"
    width="80%"
    append-to-body
    :before-close="cancel"
    :close-on-click-modal="false"
  >
    <div class="app-container">
      <!-- 搜索工作栏 -->
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
        <el-form-item label="角色" prop="userType">
          <el-select
            v-model="queryParams.userType"
            placeholder="请选择角色"
            clearable
            size="small"
          >
            <el-option
              v-for="dict in this.getDictDatas(DICT_TYPE.COLLEGE_USER_ROLE)"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="审批状态" prop="approvalStatus">
          <el-select
            v-model="queryParams.approvalStatus"
            placeholder="请选择审批状态"
            clearable
            size="small"
          >
            <el-option
              v-for="dict in this.getDictDatas(
                DICT_TYPE.ATTENDANCE_APPROVAL_STATUS
              )"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <!-- 操作工具栏 -->
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <!-- v-hasPermi="['collegebase:classroom-info:create']" -->
          <el-button type="primary" plain @click="audit(0, sourceId)"
            >审核</el-button
          >
        </el-col>
      </el-row>

      <!-- 列表 -->
      <el-table
        v-loading="loading"
        :data="list"
        highlight-current-row
        @select="rowClick"
      >
        <el-table-column label width="35">
          <template slot-scope="scope">
            <!-- 已通过不可选择 -->
            <div v-if="scope.row.approvalStatus == 2">
              <el-radio :label="scope.row.id" v-model="sourceId"></el-radio>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="学院" align="center" prop="collegeName" />
        <el-table-column label="姓名" align="center" prop="userName" />
        <el-table-column label="角色" align="center" prop="userType">
          <template slot-scope="scope">
            <dict-tag
              :type="DICT_TYPE.COLLEGE_USER_ROLE"
              :value="scope.row.userType"
            />
          </template>
        </el-table-column>
        <el-table-column label="联系方式" align="center" prop="userPhone" />
        <el-table-column label="请假天数" align="center" prop="leaveDays" />
        <el-table-column label="请假类型" align="center" prop="reasonName" />
        <el-table-column
          label="请假开始时间"
          align="center"
          prop="leaveStartTime"
          show-overflow-tooltip
        />
        <el-table-column
          label="请假结束时间"
          align="center"
          prop="leaveEndTime"
          show-overflow-tooltip
        />
        <!-- <el-table-column label="状态" align="center" prop="approvalStatus" /> -->
        <el-table-column label="状态" align="center" prop="approvalStatus">
          <template slot-scope="scope">
            <dict-tag
              :type="DICT_TYPE.ATTENDANCE_APPROVAL_STATUS"
              :value="scope.row.approvalStatus"
            />
          </template>
        </el-table-column>
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template slot-scope="scope">
            <!-- v-hasPermi="['collegebase:classroom-info:update']" -->
            <el-button
              size="mini"
              type="text"
              icon="el-icon-view"
              @click="audit(1, scope.row)"
              >查看</el-button
            >
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="handleDelete(scope.row)"
              v-hasPermi="['collegebase:classroom-info:delete']"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNo"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <!-- 添加修改组件 -->
    </div>
    <el-dialog
      :title="aduitFlag == 0 ? '审核' : '查看'"
      append-to-body
      :visible.sync="dialogVisible"
      width="30%"
      :close-on-click-modal="false"
    >
      <div>
        <el-row>
          <div class="group-name">基本信息</div>
          <el-col class="item" :span="12"
            >学院:{{ attendanceManagementDetail.collegeName }}</el-col
          >
          <el-col
            class="item"
            :span="12"
            v-if="attendanceManagementDetail.userType == 4"
            >系部：{{ attendanceManagementDetail.departmentName }}</el-col
          >
          <el-col class="item" :span="12"
            >请假人姓名:{{ attendanceManagementDetail.userName }}</el-col
          >
          <el-col class="item" :span="12"
            >联系方式:{{ attendanceManagementDetail.userPhone }}</el-col
          >
          <el-col class="item" :span="12"
            >角色:<dict-tag
              :type="DICT_TYPE.COLLEGE_USER_ROLE"
              :value="attendanceManagementDetail.userType"
          /></el-col>
          <el-col class="item" :span="12"
            >请假天数:{{ attendanceManagementDetail.leaveDays }}天</el-col
          >
          <el-col class="item" :span="12"
            >请假开始时间:{{
              attendanceManagementDetail.leaveStartTime
            }}</el-col
          >
          <el-col class="item" :span="12"
            >请假结束时间:{{ attendanceManagementDetail.leaveEndTime }}</el-col
          >
          <el-col class="item" :span="12"
            >请假类型:{{ attendanceManagementDetail.reasonName }}</el-col
          >
          <el-col class="item" :span="12"
            >原因描述:{{ attendanceManagementDetail.leaveExplain }}</el-col
          >
        </el-row>
        <el-row v-if="aduitFlag == 0">
          <div class="group-name">审核信息</div>
          <el-col :span="4">审核状态</el-col>
          <el-col :span="20">
            <el-radio-group v-model="status">
              <el-radio :label="3">通过</el-radio>
              <el-radio :label="4">不通过</el-radio>
            </el-radio-group>
          </el-col>
          <el-col :span="24" style="margin: 10px 0">审核详情</el-col>
          <el-col :span="24">
            <el-input
              type="textarea"
              :rows="2"
              placeholder="请输入内容"
              v-model="description"
            >
            </el-input>
          </el-col>
        </el-row>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmCheck">确 定</el-button>
      </span>
    </el-dialog>
  </el-dialog>
</template>

<script>
import {
  getAttendanceManagementPage,
  getAttendanceManagement,
  deleteAttendanceManagement,
  checkAttendanceManagement,
} from "@/api/teacherSide/audit.js";
import { getDictDatas, DICT_TYPE } from "@/utils/dict";
import { randomUUID } from "crypto";
// import { log } from 'console';
export default {
  name: "",
  components: {},
  data() {
    return {
      auditTitle: "",
      description: "",
      status: 3, //  <!-- 3 =审核通过  4 = 审核不通过 -->
      dialogVisible: false,
      attendanceManagementDetail: {},
      showSearch: true,
      loading: false,
      total: 0,
      sourceId: "",
      list: [{ name: "张上", id: 1 }],
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        classroomName: null,
        approvalStatus: null,
        userType: null
      },
      value1: "",
      // tags: [
      //   { name: "标签一", type: "" },
      //   { name: "标签二", type: "success" },
      //   { name: "标签三", type: "info" },
      //   { name: "标签四", type: "warning" },
      //   { name: "标签五", type: "danger",inputVisible:false},
      // ],
      inputVisible: false,
      submitting: false,
      list: [],
      aduitFlag: "",
    };
  },
  created() {
    this.getList();
  },
  props: {
    // 是否显示弹出层
    show: {
      type: Boolean,
      default: false,
    },
    // 显示弹出层标题
    title: {
      type: String,
      default: "",
    },
    tags: {
      type: Array,
    },
  },
  methods: {
    // 审核请假
    confirmCheck() {
      if (this.aduitFlag == 1) {
        this.dialogVisible = false;
        return;
      }
      let params = {
        approvalStatus: this.status,
        id: this.attendanceManagementDetail.id,
        remark: this.description,
      };
      checkAttendanceManagement(params).then((res) => {
        if (res.code == 0) {
          this.attendanceManagementDetail = {};
          this.getList();
          this.description = "";
          this.sourceId = "";
          this.$modal.msgSuccess("审核成功");
        }
      });
      this.dialogVisible = false;
    },
    rowClick(row) {
      this.sourceId = row.id;
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const id = row.id;
      getAttendanceManagement(id).then((response) => {
        let form = response.data;
        // this.open = true;
        // this.title = "修改学员信息";
        // this.$refs.editDialog.initData(form);
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal
        .confirm('是否确认删除学员信息编号为"' + id + '"的数据项?')
        .then(function () {
          return deleteAttendanceManagement(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();

    },
    // 查看信息或审核
    audit(flag, row) {
      this.aduitFlag = flag;
      let id;
      if (flag == 0) {
        if (!this.sourceId) {
          this.$message.error("请勾选信息");
          return;
        }
        id = row;
      } else {
        this.sourceId = "";
        id = row.id;
      }
      getAttendanceManagement(id).then((response) => {
        let form = response.data;
        this.attendanceManagementDetail = response.data;
      });
      this.dialogVisible = true;
      this.$nextTick(() => { });
    },
    getList() {
      getAttendanceManagementPage({
        ...this.queryParams,
        copySendId: this.$store.getters.userId,
      }).then((res) => {
        this.list = res.data.list;
        this.total = res.data.total;
      });
    },
    async handleInputConfirm(tag) {
      if (this.submitting) return;
      this.submitting = true;
      if (tag && tag.name) {
        tag.inputVisible = false;
        //  const res = await createClassroomFunction({functionName:tag.name})
        //  if(res.data){
        //   this.$parent.getTags();
        //  }
        this.submitting = false;
      } else {
        // this.$message.error("请输入功能名称");
        this.submitting = false;
      }
    },
    handleClose(tag) {
      this.tags.forEach(async (e, i) => {
        if (e.name == tag.name) {
          //  const res =  await deleteClassroomFunction(tag.id)
          //  if(res.data){
          //   this.$parent.getTags();
          //  }
          this.tags.splice(i, 1);
        }
      });
      // this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
    },
    showInput() {
      this.inputVisible = true;
      this.tags.push({ name: "", type: "danger", inputVisible: true });
      this.submitting = false;
      this.$nextTick(() => {
        // console.log(this.$refs.saveTagInput)
        this.$refs.saveTagInput.at(-1).focus();
      });
    },
    cancel() {
      this.$emit("update:show", false);
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (!valid) {
          return;
        }
        // 修改的提交
        if (this.form.id != null) {
          updateClassroomInfo(this.form).then((response) => {
            this.$modal.msgSuccess("修改成功");
            this.cancel();
            this.$emit("success");
          });
          return;
        }
        // 添加的提交
        createClassroomInfo(this.form).then((response) => {
          this.$modal.msgSuccess("新增成功");
          this.cancel();
          this.$emit("success");
        });
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
.group-name {
  padding: 10px;
  border-bottom: 1px solid #f5f5f5;
  margin-bottom: 20px;
  font-size: 16px;
  font-weight: bold;
}
.item {
  margin: 10px 0;
}
</style>
